<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>COLLADA Scene Viewer</title>
  <script type="text/javascript" src="scripts/spidergl.js"></script>
<script type="text/javascript" src="scripts/collada.js"></script>

<script id="PHONG_VERTEX_SHADER" type="x-shader/x-vertex">
#ifdef GL_ES
precision highp float;
#endif

uniform   mat4 u_model_view_projection_mat;
uniform   mat4 u_model_view_mat;
uniform   mat3 u_view_normal_mat;

attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_texcoord;

varying   vec3 v_view_position;
varying   vec3 v_view_normal;
varying   vec2 v_texcoord;

void main(void)
{
	v_view_position = (u_model_view_mat  * a_position).xyz;
	v_view_normal   = u_view_normal_mat * a_normal;
	v_texcoord      = a_texcoord;

	gl_Position = u_model_view_projection_mat * a_position;
}
    </script>

<script id="PHONG_FRAGMENT_SHADER" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif

uniform vec4      u_view_light_dir;

uniform vec4      u_emission;
uniform vec4      u_ambient;
uniform vec4      u_diffuse;
uniform vec4      u_specular;
uniform float     u_shininess;

uniform sampler2D s_emission;
uniform sampler2D s_ambient;
uniform sampler2D s_diffuse;
uniform sampler2D s_specular;
uniform sampler2D s_shininess;

varying vec3      v_view_position;
varying vec3      v_view_normal;
varying vec2      v_texcoord;

void main(void)
{
	vec3  matEmission  = u_emission.xyz + texture2D(s_emission, v_texcoord).xyz;
	vec3  matAmbient   = u_ambient.xyz;
	vec3  matDiffuse   = u_diffuse.xyz * texture2D(s_diffuse, v_texcoord).xyz;
	vec3  matAccessibility = texture2D(s_ambient, v_texcoord).xyz;
	vec3  matSpecular  = u_specular.xyz * texture2D(s_specular, v_texcoord).xyz;
	float matShininess = u_shininess + texture2D(s_shininess, v_texcoord).x;

	vec3  view_normal  = normalize(v_view_normal);
	float n_dot_l      = abs(dot(view_normal, -u_view_light_dir.xyz));
	if (u_view_light_dir.w > 0.5) n_dot_l = 1.0;
	vec3  refl_vector  = reflect(u_view_light_dir.xyz, view_normal);
	vec3  view_vector  = normalize(-v_view_position);

	vec3  emission = matEmission;
	vec3  ambient  = matAmbient * matDiffuse;
	vec3  diffuse  = matDiffuse * n_dot_l * matAccessibility;
	vec3  specular = matSpecular * pow(max(dot(refl_vector, view_vector), 0.0), u_shininess);

	vec3  color = emission + ambient + diffuse + specular;

	gl_FragData[0] = vec4(color, 1.0);
}
</script>
    
<script type="text/javascript" src="scripts/jiang.js"></script>
</head>
<body id="index" onload="changeScene('tCrue')"> 
 <canvas id="Jiang_Canvas" width="680" height="580"></canvas> 
</body>
</html>